package ua.tach.shortl.logic;

import ua.tach.shortl.Renderer;

import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;

/*
 * 3 types of tree - derevo, yolka and house :)
 */

public class Tree {
	private static final float TREE_SIZE = 0.07f;
	private Vector2 place;
	private float rot;
	private int type;
	private Vector3 color;

	public Tree (Vector2 p, int t, float r, Vector3 c) {
		place = new Vector2(p);
		type = t;
		rot=r;
		color = new Vector3(c);
	}
	
	public void move (float px, float py) {
		place.add(px, py);
	}

	public boolean here (Vector2 p) {
		return (place.dst2(p) < ((type==2)?TREE_SIZE*2:TREE_SIZE));
	}

	public void render (GL10 gl) {
		Renderer.toLoad[type+2].tx.bind();
		gl.glPushMatrix();
		gl.glTranslatef(place.x, 0, place.y);
		gl.glRotatef(rot, 0, rot, 0);
		gl.glColor4f(color.x,color.y,color.z,1);
		Renderer.toLoad[type+2].m.render(GL10.GL_TRIANGLES);
		gl.glPopMatrix();
	}
}
